(function(){
    //文字初始化
    var deviceWidth = document.documentElement.clientWidth;
    if (deviceWidth > 750) deviceWidth = 750;
    document.documentElement.style.fontSize = deviceWidth / 7.5 + 'px';

})()

//vido播放器的改造

window.onload = function(){
    $('.video-poster').on('touchstart',function(e){
        var controlLeft;
        var _controlLeft = parseInt($('.video-chose-player').offset().left) -parseInt($('.video-chose').offset().left);
        var e = e || window.event;
        isMove = true;
        var _x =  e.changedTouches[0].pageX;

        $('.video-poster').on('touchmove',function(e) {
            /* Act on the event */
            var e = e || window.event;
            var x = e.changedTouches[0].pageX  - _x;
            controlLeft = parseInt($('.video-chose-player').css('left')) ;
            var maxx = controlLeft + x;
            var $x = _controlLeft + x;

            if (maxx >= 0 && maxx < parseInt($('.video-chose').css('width')) ) {
                if ($x >= 0 && $x < parseInt($('.video-chose').css('width'))) {
                    $('.video-chose-player').css({
                        left: $x + 'px'
                    });
                    $('.video-jindu').css({
                        width:$x + 'px'
                    });
                    video[0].currentTime = $x*(video[0].duration/parseInt($('.video-chose').css('width'))) ;
                };   
            };
               

        });
    })
    $('.video-poster').on('touchend',function(e){
        isMove = false;
    });
    $('.video-chose').on('click',function(e){
        var e = e || window.event;
        var x = e.clientX;
            x = x - parseInt($('.video-chose').offset().left);
            $('.video-chose-player').css({
                    left: x + 'px'
            });
            $('.video-jindu').css({
                        width: x + 'px'
            });
            video[0].currentTime = x*(video[0].duration/parseInt($('.video-chose').css('width')));
    });
    var video = $('#videoID');
	
    
    var t = setInterval(function(){

        var Tx = video[0].currentTime*(parseInt($('.video-chose').css('width'))/video[0].duration);
        $('.video-chose-player').css({
                    left: Tx  + 'px'
            });
        $('.video-jindu').css({
                    width: Tx  + 'px'
        });

        if (Math.floor(video[0].currentTime - (parseInt(video[0].currentTime/60))*60)<10) {
           var Tmiao = '0' + Math.floor(video[0].currentTime - (parseInt(video[0].currentTime/60))*60)
           var videoTime = parseInt(video[0].currentTime/60) +':'+ Tmiao;
        }else{
            var videoTime = parseInt(video[0].currentTime/60) +':'+ Math.floor(video[0].currentTime - (parseInt(video[0].currentTime/60))*60);
        }
        $('.time-begin').html(videoTime);
		var videoTimeEnd =  parseInt(video[0].duration/60) +':'+ Math.floor(video[0].duration - (parseInt(video[0].duration/60))*60);
		$('.time-end').html(videoTimeEnd);
        if (video[0].ended) {
            $('.video-player').removeClass('video-player-active');
        }
    }, 1000);

    $('.video-player').on('click', function() {
        if (video[0].paused) {
            video[0].play();
            $('.video-player').addClass('video-player-active');
        } else {
            video[0].pause();
            $('.video-player').removeClass('video-player-active');
        }
        return false;
    });
    $('.video-all').on('click',function(){
        // 在支持全屏的浏览器中启动全屏
        // 整个页面
        launchFullScreen(document.documentElement);
        // 某个元素
        launchFullScreen(document.getElementById("videoID"));
    })

   document.onkeydown = function(event) {
             var e = event || window.event || arguments.callee.caller.arguments[0];
             if (e && e.keyCode == 27) { // 按 Esc 
                 // 调用退出全屏方法!
                exitFullscreen();
				
				
             }
			 
             
    };
}

// 找到支持的方法, 使用需要全屏的 element 调用
function launchFullScreen(element) {
  if(element.requestFullscreen) {
    element.requestFullscreen();
  } else if(element.mozRequestFullScreen) {
    element.mozRequestFullScreen();
  } else if(element.webkitRequestFullscreen) {
    element.webkitRequestFullscreen();
  } else if(element.msRequestFullscreen) {
    element.msRequestFullscreen();
  }
}
// 退出 fullscreen
function exitFullscreen() {
  if(document.exitFullscreen) {
    document.exitFullscreen();
  } else if(document.mozExitFullScreen) {
    document.mozExitFullScreen();
  } else if(document.webkitExitFullscreen) {
    document.webkitExitFullscreen();
  }
}

 
